import request from '@/utils/request'

/**
 * 赛程管理API接口
 */

// 分页查询赛程列表
export function getSchedulePage(currentPage, pageSize, queryParams) {
  return request({
    url: `/api/schedules/page/${currentPage}/${pageSize}`,
    method: 'get',
    params: queryParams
  })
}

// 根据ID查询赛程详情
export function getScheduleById(scheduleId) {
  return request({
    url: `/api/schedules/${scheduleId}`,
    method: 'get'
  })
}

// 创建赛程
export function createSchedule(scheduleData) {
  return request({
    url: '/api/schedules',
    method: 'post',
    data: scheduleData
  })
}

// 更新赛程信息
export function updateSchedule(scheduleData) {
  return request({
    url: '/api/schedules',
    method: 'put',
    data: scheduleData
  })
}

// 删除赛程
export function deleteSchedule(scheduleId) {
  return request({
    url: `/api/schedules/${scheduleId}`,
    method: 'delete'
  })
}

// 开始比赛
export function startSchedule(scheduleId) {
  return request({
    url: `/api/schedules/${scheduleId}/start`,
    method: 'put'
  })
}

// 结束比赛
export function endSchedule(scheduleId) {
  return request({
    url: `/api/schedules/${scheduleId}/end`,
    method: 'put'
  })
}

// 延期比赛
export function postponeSchedule(scheduleId, newStartTime, newEndTime) {
  return request({
    url: `/api/schedules/${scheduleId}/postpone`,
    method: 'put',
    params: { newStartTime, newEndTime }
  })
}

// 取消比赛
export function cancelSchedule(scheduleId) {
  return request({
    url: `/api/schedules/${scheduleId}/cancel`,
    method: 'put'
  })
}

// 分配裁判
export function assignReferee(scheduleId, refereeId) {
  return request({
    url: `/api/schedules/${scheduleId}/assign-referee`,
    method: 'put',
    params: { refereeId }
  })
}

// 更换裁判
export function changeReferee(scheduleId, newRefereeId) {
  return request({
    url: `/api/schedules/${scheduleId}/change-referee`,
    method: 'put',
    params: { newRefereeId }
  })
}

// 根据项目ID查询赛程列表
export function getSchedulesByProjectId(projectId) {
  return request({
    url: `/api/schedules/project/${projectId}`,
    method: 'get'
  })
}

// 根据场地ID查询赛程列表
export function getSchedulesByVenueId(venueId) {
  return request({
    url: `/api/schedules/venue/${venueId}`,
    method: 'get'
  })
}

// 获取今日赛程
export function getTodaySchedules() {
  return request({
    url: '/api/schedules/today',
    method: 'get'
  })
}

// 获取本周赛程
export function getWeekSchedules() {
  return request({
    url: '/api/schedules/week',
    method: 'get'
  })
}

// 获取即将开始的赛程
export function getUpcomingSchedules() {
  return request({
    url: '/api/schedules/upcoming',
    method: 'get'
  })
}

// 获取赛程状态统计
export function getScheduleStatistics() {
  return request({
    url: '/api/schedules/statistics',
    method: 'get'
  })
}

// 获取赛程状态列表
export function getScheduleStatuses() {
  return request({
    url: '/api/schedules/statuses',
    method: 'get'
  })
}

// 检查场地可用性
export function checkVenueAvailability(venueId, startTime, endTime) {
  return request({
    url: '/api/schedules/check-venue',
    method: 'get',
    params: { venueId, startTime, endTime }
  })
}

// 检查裁判可用性
export function checkRefereeAvailability(refereeId, startTime, endTime) {
  return request({
    url: '/api/schedules/check-referee',
    method: 'get',
    params: { refereeId, startTime, endTime }
  })
}

// 获取我的赛程（裁判专用）
export function getMySchedules() {
  return request({
    url: '/api/schedules/my-schedules',
    method: 'get'
  })
}

// 根据日期范围查询赛程
export function getSchedulesByDateRange(startDate, endDate) {
  return request({
    url: '/api/schedules/date-range',
    method: 'get',
    params: { startDate, endDate }
  })
}

// 批量更新赛程状态
export function batchUpdateScheduleStatus(scheduleIds, status) {
  return request({
    url: '/api/schedules/batch-update-status',
    method: 'put',
    data: scheduleIds,
    params: { status }
  })
}

// 获取赛程日历数据
export function getScheduleCalendarData(year, month) {
  return request({
    url: '/api/schedules/calendar',
    method: 'get',
    params: { year, month }
  })
}

// 导出赛程表
export function exportSchedule(queryParams) {
  return request({
    url: '/api/schedules/export',
    method: 'get',
    params: queryParams,
    responseType: 'blob'
  })
}

// 复制赛程
export function copySchedule(scheduleId, newStartTime, newEndTime) {
  return request({
    url: `/api/schedules/${scheduleId}/copy`,
    method: 'post',
    params: { newStartTime, newEndTime }
  })
}